﻿using Terraria.ID;
using Terraria;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using EAS.Common.ModUtils;

namespace EAS.Content.Projectiles
{
    public class CthulhuEmblemProjectile : ModProjectile
    {
        private float rot;
        private Vector2 rotVec = new(0.0f, 150.0f);

        public override void SetDefaults()
        {
            Projectile.width = 8;
            Projectile.height = 8;
            Projectile.aiStyle = -1;
            Projectile.tileCollide = false;
            Projectile.ownerHitCheck = true;
            Projectile.ignoreWater = true;
            Projectile.penetrate = -1;
            Projectile.timeLeft = 28;
        }

        public override void AI()
        {
            rot += 0.5f;
            Projectile.Center = Main.player[Projectile.owner].Center + AccUtil.RotateVector(new Vector2(), rotVec, rot + Projectile.ai[0] * 3.14f);
            if (Main.rand.NextBool(1, 5))
            {
                float x = Projectile.velocity.X / 3f;
                float y = Projectile.velocity.Y / 3f;
                int dust = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.GemRuby, 0.0f, 0.0f, 0, new Color(), 1.4f);
                Main.dust[dust].position.X = Projectile.Center.X - x;
                Main.dust[dust].position.Y = Projectile.Center.Y - y;
                Main.dust[dust].noGravity = true;
                Main.dust[dust].scale += Main.rand.NextFloat() * 1f;
            }
        }
    }
}
